﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Configuration;

namespace SharpShare.Configuration {
    public class StorageProviderNameConverter : StringConverter {
        public override TypeConverter.StandardValuesCollection GetStandardValues(ITypeDescriptorContext context) {
            var config = (System.Configuration.Configuration)TypeDescriptor.GetProperties(context.Instance)["CurrentConfiguration"].GetValue(context.Instance);
            if (config == null) {
                return new StandardValuesCollection(new string[] { });
            }
            SharpShareSectionGroup mainGroup = SharpShareSectionGroup.GetSectionGroup(config);
            TypeConverter.StandardValuesCollection standardValues = new StandardValuesCollection(
                mainGroup.StorageProviders.Select(s => s.Name).ToList()
            );
            return standardValues;
        }
        public override bool GetStandardValuesSupported(ITypeDescriptorContext context) {
            return true;
        }
    }
}
